home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1993…ch: Other People's Memory / ADC Developer CD (1993-03) (''Other People's Memory'')_iso / Dev.CD Mar 93.iso / Technical Documentation / Sample Code / DTS.Lib & Samples / DTS.Lib / ViewHierarchy.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-22  |  26.3 KB  |  1,020 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** Program:     DTS.Lib
  5. ** File:        viewhierarchy.c
  6. ** Written by:  Eric Soldan
  7. **
  8. ** Copyright © 1990-1992 Apple Computer, Inc.
  9. ** All rights reserved.
  10. */
  11.  
  12.  
  13.  
  14. /*****************************************************************************/
  15.  
  16.  
  17.  
  18. #include "DTS.Lib2.h"
  19. #include "DTS.Lib.Common.h"
  20. #include "DTS.Lib.protos.h"
  21.  
  22. #ifndef __CTLHANDLER__
  23. #include "CtlHandler.h"
  24. #endif
  25.  
  26. #ifndef __ERRORS__
  27. #include <Errors.h>
  28. #endif
  29.  
  30. #ifndef __FONTS__
  31. #include <Fonts.h>
  32. #endif
  33.  
  34. #ifndef __LISTCONTROL__
  35. #include "ListControl.h"
  36. #endif
  37.  
  38. #ifndef __RESOURCES__
  39. #include <Resources.h>
  40. #endif
  41.  
  42. #ifndef __STDIO__
  43. #include <StdIO.h>
  44. #endif
  45.  
  46. #ifndef __STRING__
  47. #include <String.h>
  48. #endif
  49.  
  50. #ifndef THINK_C
  51. #ifndef __STRINGS__
  52. #include <Strings.h>
  53. #endif
  54. #endif
  55.  
  56. #ifndef __TEXTEDITCONTROL__
  57. #include "TextEditControl.h"
  58. #endif
  59.  
  60. #ifndef __UTILITIES__
  61. #include "Utilities.h"
  62. #endif
  63.  
  64.  
  65.  
  66. /*****************************************************************************/
  67.  
  68.  
  69.  
  70. typedef struct ViewHierFileTypeRec {
  71.     FileStateRec    fileState;
  72.     ConnectRec        connect;
  73.     ViewDoc            vh;
  74. } ViewHierFileTypeRec;
  75.  
  76.  
  77. extern short            gPrintPage;            /* Non-zero means we are printing. */
  78. extern TreeObjProcPtr    gTreeObjMethods[];
  79. extern Cursor            *gCursorPtr;
  80.  
  81. static void        VHContentClick(WindowPtr window, EventRecord *event, Boolean firstClick);
  82. static Boolean    VHContentKey(WindowPtr window, EventRecord *event, Boolean *passThrough);
  83. static OSErr    VHImageDocument(FileRecHndl frHndl);
  84. static OSErr    VHInitContent(FileRecHndl frHndl, WindowPtr window);
  85. static Boolean    VHDisplayFilter(TEHandle teHndl, EventRecord *event, Boolean *handled);
  86. static void        VHNewView(FileRecHndl frHndl, char *newText, short newTextLen, Boolean updatePList);
  87. static OSErr    VHUpdateInfo(FileRecHndl frHndl, Boolean updatePList);
  88. static Boolean    VHWindowCursor(FileRecHndl frHndl, WindowPtr window, Point globalPt);
  89.  
  90.  
  91.  
  92. /*****************************************************************************/
  93. /*****************************************************************************/
  94.  
  95.  
  96.  
  97. /* This is called when a mouse-down event occurs in the content of a window.
  98. ** Other applications might want to call FindControl, TEClick, etc., to
  99. ** further process the click. */
  100.  
  101. #pragma segment Window
  102. void    VHContentClick(WindowPtr window, EventRecord *event, Boolean firstClick)
  103. {
  104. #pragma unused (firstClick)
  105.  
  106.     FileRecHndl        frHndl;
  107.     ControlHandle    ctl;
  108.     short            ctlNum, action, len, selStart;
  109.     ListHandle        plist, clist;
  110.     TEHandle        te, display;
  111.     char            newText[33];
  112.     Point            cell;
  113.  
  114.     frHndl = (FileRecHndl)GetWRefCon(window);
  115.  
  116.     ctlNum = IsCtlEvent(window, event, &ctl, &action);
  117.     switch (ctlNum) {
  118.         case 1:
  119.             display = (*frHndl)->d.vh.display;
  120.             te = CTEFindActive(window);
  121.             if (!te)
  122.                 te = display;
  123.             ctl = CTEViewFromTE(te);
  124.             if (te == display) {
  125.                 CTEActivate(true, te);
  126.                 CLActivate(false, CLFindActive(window));
  127.                 CTESetSelect(0, (*te)->teLength, display);
  128.             }
  129.             len = (*te)->selEnd - (selStart = (*te)->selStart);
  130.             if (len > 32)
  131.                 len = 32;
  132.             BlockMove(*((*te)->hText) + selStart, newText, len);
  133.             VHNewView(frHndl, newText, len, true);
  134.             break;
  135.         case 2:
  136.             if (action == 1) {
  137.                 plist = (*frHndl)->d.vh.plist;
  138.                 cell  = LLastClick(plist);
  139.                 len   = 8;
  140.                 LGetCell(newText, &len, cell, plist);
  141.                 VHNewView(frHndl, newText, len, false);
  142.             }
  143.             break;
  144.         case 4:
  145.             if (action == 1) {
  146.                 clist = (*frHndl)->d.vh.clist;
  147.                 cell  = LLastClick(clist);
  148.                 len   = 8;
  149.                 LGetCell(newText, &len, cell, clist);
  150.                 VHNewView(frHndl, newText, len, true);
  151.             }
  152.             break;
  153.     }
  154. }
  155.  
  156.  
  157.  
  158. /*****************************************************************************/
  159.  
  160.  
  161.  
  162. /* This is called when a key event occurs and it is determined that it isn't
  163. ** a menu key. */
  164.  
  165. #pragma segment Window
  166. Boolean    VHContentKey(WindowPtr window, EventRecord *event, Boolean *passThrough)
  167. {
  168. #pragma unused (passThrough)
  169.  
  170.     FileRecHndl        frHndl;
  171.     char            key;
  172.     ControlHandle    ctl;
  173.     short            action, selStart, len;
  174.     TEHandle        te, display;
  175.     char            newText[33];
  176.  
  177.     frHndl = (FileRecHndl)GetWRefCon(window);
  178.     key = event->message & charCodeMask;
  179.  
  180.     if ((key == chEnter) || (key == chReturn)) {
  181.         SelectButton(ctl = (*frHndl)->d.vh.newView);
  182.         display = (*frHndl)->d.vh.display;
  183.         te = CTEFindActive(window);
  184.         if (!te)
  185.             te = display;
  186.         ctl = CTEViewFromTE(te);
  187.         if (te == display) {
  188.             CTEActivate(true, te);
  189.             CLActivate(false, CLFindActive(window));
  190.             CTESetSelect(0, (*te)->teLength, display);
  191.         }
  192.         len = (*te)->selEnd - (selStart = (*te)->selStart);
  193.         if (len > 32)
  194.             len = 32;
  195.         BlockMove(*((*te)->hText) + selStart, newText, len);
  196.         VHNewView(frHndl, newText, len, true);
  197.         return(true);
  198.     }
  199.  
  200.     return(IsCtlEvent(window, event, &ctl, &action));
  201. }
  202.  
  203.  
  204.  
  205. /*****************************************************************************/
  206.  
  207.  
  208.  
  209. /* Image the document into the current port. */
  210.  
  211. #pragma segment Window
  212. OSErr    VHImageDocument(FileRecHndl frHndl)
  213. {
  214. #pragma unused (frHndl)
  215.  
  216.     WindowPtr        thePort;
  217.  
  218.     GetPort(&thePort);
  219.  
  220.     if (!gPrintPage) {                                        /* If not printing... */
  221.         DoDrawControls(thePort, false);                        /* Draw the content controls. */
  222.         OutlineControl((*frHndl)->d.vh.newView);
  223.     }
  224.     else {
  225.         gPrintPage = 0;
  226.     }
  227.  
  228.     return(noErr);
  229. }
  230.  
  231.  
  232.  
  233. /*****************************************************************************/
  234.  
  235.  
  236.  
  237. /* This function does the remaining window initialization. */
  238.  
  239. #pragma segment Window
  240. OSErr    VHInitContent(FileRecHndl frHndl, WindowPtr window)
  241. {
  242.     FileRecPtr        frPtr;
  243.     FileRecHndl        refFrHndl;
  244.     OSErr            err;
  245.     WindowPtr        oldPort;
  246.     Rect            ctlRect, brdrRect, viewRect, destRect, listRect1, listRect2, newDisplay;
  247.     short            mode, fnum;
  248.     TEHandle        dump, display;
  249.     ListHandle        plist, clist;
  250.     ControlHandle    newView;
  251.  
  252.     err = noErr;
  253.  
  254.     GetPort(&oldPort);
  255.     SetPort(window);
  256.  
  257.     GetFNum("\pMonaco", &fnum);
  258.     TextFont(fnum);
  259.     TextSize(9);
  260.  
  261.     ctlRect = window->portRect;
  262.     --ctlRect.top;
  263.     --ctlRect.left;
  264.     ctlRect.right  = ctlRect.left + 298;
  265.     ++ctlRect.bottom;
  266.     InsetRect(&ctlRect, 10, 10);
  267.     brdrRect = ctlRect;
  268.     viewRect = ctlRect;
  269.     InsetRect(&viewRect, 4, 4);
  270.     destRect = viewRect;
  271.     destRect.right -= 2;    /* This fixes a TextEdit problem where the
  272.                             ** view has to be a little outside the dest on
  273.                             ** the right, or else characters are clipped. */
  274.  
  275.     mode = (cteReadOnly | cteVScroll | cteActive | cteShowActive);
  276.     CTENew(rTECtl, window, &dump, &ctlRect, &destRect, &viewRect, &brdrRect, 32000, mode);
  277.     if (dump) {
  278.         (*dump)->txFont = fnum;
  279.         (*dump)->txSize = 9;
  280.     }
  281.     else err = memFullErr;
  282.  
  283.     SetRect(&newDisplay, ctlRect.right + 26, ctlRect.top, ctlRect.right + 116, ctlRect.top + 20);
  284.     brdrRect = newDisplay;
  285.     viewRect = newDisplay;
  286.     InsetRect(&viewRect, 4, 4);
  287.     destRect = viewRect;
  288.     destRect.right -= 2;
  289.     mode = (cteActive | cteShowActive | cteTabSelectAll);
  290.     CTENew(rTECtl, window, &display, &newDisplay, &destRect, &viewRect, &brdrRect, 10, mode);
  291.     if (display) {
  292.         CTESetKeyFilter(display, VHDisplayFilter);
  293.         (*display)->txFont = fnum;
  294.         (*display)->txSize = 9;
  295.     }
  296.     else err = memFullErr;
  297.  
  298.     ctlRect.top += 38;
  299.  
  300.     ctlRect.left  = ctlRect.right + 26;
  301.     ctlRect.right = ctlRect.left  + 70;
  302.     listRect1 = ctlRect;
  303.  
  304.     ctlRect.left  = ctlRect.right + 26;
  305.     ctlRect.right = ctlRect.left  + 70;
  306.     listRect2 = ctlRect;
  307.  
  308.     mode = (clVScroll | clShowActive | clDrawIt);
  309.  
  310.     clist = CLNew(rListCtl, &listRect2, 0, 1, 11, 80, 0, window, mode);
  311.     if (clist)
  312.         (*clist)->selFlags = lOnlyOne;
  313.     else err = memFullErr;
  314.     plist = CLNew(rListCtl, &listRect1, 0, 1, 11, 80, 0, window, mode);
  315.     if (plist)
  316.         (*plist)->selFlags = lOnlyOne;
  317.     else
  318.         err = memFullErr;
  319.  
  320.     newView = GetNewControl(rNewViewCtl, window);
  321.     if (!newView)
  322.         err = resNotFound;
  323.  
  324.     frPtr = *frHndl;
  325.     frPtr->d.vh.dump    = dump;
  326.     frPtr->d.vh.display = display;
  327.     frPtr->d.vh.plist   = plist;
  328.     frPtr->d.vh.clist   = clist;
  329.     frPtr->d.vh.newView = newView;
  330.  
  331.     if  (!err) {
  332.         refFrHndl = mDerefRoot(frPtr->d.vh.root)->frHndl;
  333.         NewWindowTitle(window, (*refFrHndl)->fileState.fss.name);
  334.         VHUpdateInfo(frHndl, true);
  335.     }
  336.  
  337.     SetPort(oldPort);
  338.     return(err);
  339. }
  340.  
  341.  
  342.  
  343. /*****************************************************************************/
  344.  
  345.  
  346.  
  347. #pragma segment Window
  348. static Boolean    VHWindowCursor(FileRecHndl frHndl, WindowPtr window, Point globalPt)
  349. {
  350. #pragma unused (frHndl, window, globalPt)
  351.  
  352.     SetCursor(gCursorPtr = &qd.arrow);
  353.     return(true);
  354. }
  355.  
  356.  
  357.  
  358. /*****************************************************************************/
  359.  
  360.  
  361.  
  362. #pragma segment Window
  363. Boolean    VHDisplayFilter(TEHandle teHndl, EventRecord *event, Boolean *handled)
  364. {
  365. #pragma unused (teHndl, handled)
  366.     char    key;
  367.     short    arrowKey;
  368.  
  369.     key = event->message & charCodeMask;
  370.     arrowKey = ((key >= chLeft) && (key <= chDown));
  371.     if (
  372.         (arrowKey) ||
  373.         (key == chBackspace) ||
  374.         (key == chTab) ||
  375.         ((key >= '0') && (key <= '9')) ||
  376.         ((key >= 'A') && (key <= 'F')) ||
  377.         ((key >= 'a') && (key <= 'f'))
  378.     ) {
  379.         return(false);
  380.     }
  381.  
  382.     return(true);
  383. }
  384.  
  385.  
  386.  
  387. /*****************************************************************************/
  388.  
  389.  
  390.  
  391. /* This function adds the application's controls to a window. */
  392.  
  393. #pragma segment Window
  394. void    VHNewView(FileRecHndl frHndl, char *newText, short newTextLen, Boolean updatePList)
  395. {
  396.     TEHandle    te;
  397.     short        len, i;
  398.     long        newHndl;
  399.     char        workText[33];
  400.  
  401.     if (!newText) {
  402.         newText    = workText;
  403.         newTextLen = 0;
  404.     }
  405.     if (!(len = newTextLen)) {
  406.         te = (*frHndl)->d.vh.display;
  407.         BlockMove(*((*te)->hText), newText, len = (*te)->teLength);
  408.     }
  409.  
  410.     for (newHndl = 0, i = 0; i < len; ++i) {
  411.         if ((newText[i] >= '0') && (newText[i] <= '9')) {
  412.             newHndl *= 16;
  413.             newHndl += (newText[i] - '0');
  414.             continue;
  415.         }
  416.         if ((newText[i] >= 'a') && (newText[i] <= 'f'))
  417.             newText[i] -= 32;
  418.         if ((newText[i] >= 'A') && (newText[i] <= 'F')) {
  419.             newHndl *= 16;
  420.             newHndl += (newText[i] - 'A' + 10);
  421.         }
  422.     }
  423.  
  424.     if (newHndl) {
  425.         GetHandleSize((Handle)newHndl);
  426.         if (!MemError()) {
  427.             (*frHndl)->d.vh.root = (TreeObjHndl)newHndl;
  428.             VHUpdateInfo(frHndl, updatePList);
  429.         }
  430.         else SysBeep(1);
  431.     }
  432. }
  433.  
  434.  
  435.  
  436. /*****************************************************************************/
  437.  
  438.  
  439.  
  440. /* This function adds the application's controls to a window. */
  441.  
  442. #pragma segment Window
  443. OSErr    VHUpdateInfo(FileRecHndl frHndl, Boolean updatePList)
  444. {
  445.     TreeObjHndl        root, chndl, phndl;
  446.     TEHandle        dump;
  447.     ListHandle        plist, clist;
  448.     Handle            text;
  449.     char            *cptr, *kcptr;
  450.     long            dataSize, x, v;
  451.     short            *dptr, cnum, depth, ctype;
  452.     Point            cell;
  453.     char            ctext[32], ptext[32];
  454.     RgnHandle        rgn;
  455.     Boolean            customFormat;
  456.     TreeObjProcPtr    proc;
  457.     VHFormatData    cf;
  458.  
  459.     root  = (*frHndl)->d.vh.root;
  460.     dump  = (*frHndl)->d.vh.dump;
  461.     plist = (*frHndl)->d.vh.plist;
  462.     clist = (*frHndl)->d.vh.clist;
  463.  
  464.     DoNumberTree(root);
  465.  
  466.     text = NewHandle(32767);
  467.     if (!text)
  468.         return(MemError());
  469.  
  470.     HLock(text);
  471.     cptr = kcptr = StripAddress(*text);
  472.  
  473.     ccpy   (cptr, "$");
  474.     ccathex(cptr, '0', 8, 8, (long)root);
  475.     ccatchr(cptr, 13, 2);
  476.  
  477.     ccat   (cptr, "$00:        type = $");
  478.     ccathex(cptr, '0', 4, 4, ctype = (*root)->type);
  479.     ccatchr(cptr, 13, 1);
  480.  
  481.     ccat   (cptr, "$02: numChildren = $");
  482.     ccathex(cptr, '0', 4, 4, (*root)->numChildren);
  483.     ccatchr(cptr, 13, 1);
  484.  
  485.     ccat   (cptr, "$04:    dataSize = $");
  486.     ccathex(cptr, '0', 8, 8, dataSize = (*root)->dataSize);
  487.     ccatchr(cptr, 13, 1);
  488.  
  489.     ccat   (cptr, "$08:      treeID = $");
  490.     ccathex(cptr, '0', 8, 8, (*root)->treeID);
  491.     ccatchr(cptr, 13, 1);
  492.  
  493.     ccat   (cptr, "$0C:      parent = $");
  494.     ccathex(cptr, '0', 8, 8, (long)(*root)->parent);
  495.  
  496.     customFormat = false;
  497.     if (proc = gTreeObjMethods[ctype]) {        /* If this object type has a proc...   */
  498.         cptr     += clen(cptr);
  499.         cf.text   = text;
  500.         cf.header = kcptr;
  501.         cf.data   = cptr;
  502.         customFormat = (*proc)(root, VHMESSAGE, (long)&cf);
  503.         HLock(text);
  504.         cptr = kcptr = StripAddress(*text);
  505.         cptr += clen(cptr);
  506.     }
  507.  
  508.     if (!customFormat) {
  509.         dptr = (short *)GetDataPtr(root);
  510.         for (x = 0; (cptr += clen(cptr)), (x < dataSize); x += sizeof(short)) {
  511.             v = *dptr++;
  512.             v &= 0x0000FFFF;
  513.             if ((dataSize - x) == 1)
  514.                 v &= 0x00FF;
  515.             if (!(x & 0x3F)) {
  516.                 ccatchr(cptr, 13, 2);
  517.                 ccat   (cptr, "$");
  518.                 ccathex(cptr, '0', 8, 8, x + sizeof(TreeObj));
  519.                 ccat   (cptr, ":");
  520.             }
  521.             if (!(x & 0x0F)) {
  522.                 ccatchr(cptr, 13, 1);
  523.                 ccat   (cptr, " ");
  524.             }
  525.             ccat   (cptr, " ");
  526.             ccathex(cptr, '0', 4, 4, v);
  527.             if ((cptr - kcptr) > 32000) break;
  528.         }
  529.     }
  530.  
  531.     HUnlock(text);
  532.     SetHandleSize(text, cptr - kcptr);
  533.     DisposeHandle(CTESwapText(dump, text, true));
  534.  
  535.  
  536.  
  537.     LDelRow(0, 0, clist);
  538.     LDoDraw(false, clist);
  539.     cell.h = cell.v = 0;
  540.     for (cnum = (*root)->numChildren; cnum;) {
  541.         chndl = GetChildHndl(root, --cnum);
  542.         ccpyhex(ctext, '0', 8, 8, (long)chndl);
  543.         LAddRow(1, 0, clist);
  544.         LSetCell(ctext, 8, cell, clist);
  545.     }
  546.     LDoDraw(true, clist);
  547.     rgn = NewRgn();
  548.     GetClip(rgn);
  549.     LUpdate(rgn, clist);
  550.     DisposeRgn(rgn);
  551.  
  552.  
  553.  
  554.     if (updatePList) {
  555.         LDelRow(0, 0, plist);
  556.         LDoDraw(false, plist);
  557.         cell.h = cell.v = 0;
  558.         for (depth = 0, phndl = root; phndl; phndl = (*phndl)->parent, ++depth) {
  559.             ccpyhex(ptext, '0', 8, 8, (long)phndl);
  560.             LAddRow(1, 0, plist);
  561.             LSetCell(ptext, 8, cell, plist);
  562.         }
  563.         cell.v = depth - 1;
  564.         LSetSelect(true, cell, plist);
  565.         LAutoScroll(plist);
  566.         LDoDraw(true, plist);
  567.         rgn = NewRgn();
  568.         GetClip(rgn);
  569.         LUpdate(rgn, plist);
  570.         DisposeRgn(rgn);
  571.     }
  572.     else LAutoScroll(plist);
  573. }
  574.  
  575.  
  576.  
  577. /*****************************************************************************/
  578. /*****************************************************************************/
  579.  
  580.  
  581.  
  582. #pragma segment Window
  583. OSErr    VHInitDocument(FileRecHndl frHndl)
  584. {
  585.     FileRecPtr    frPtr;
  586.     FileRecHndl    refFrHndl;
  587.     WindowPtr    window;
  588.  
  589.     frPtr = *frHndl;
  590.     frPtr->fileState.windowID                = rVHWindow;
  591.     frPtr->fileState.calcFrameRgnProc        = nil;
  592.     frPtr->fileState.contentClickProc        = VHContentClick;
  593.     frPtr->fileState.contentKeyProc          = VHContentKey;
  594.     frPtr->fileState.drawFrameProc           = nil;
  595.     frPtr->fileState.freeDocumentProc        = nil;
  596.     frPtr->fileState.freeWindowProc          = nil;
  597.     frPtr->fileState.imageProc               = VHImageDocument;
  598.     frPtr->fileState.initContentProc         = VHInitContent;
  599.     frPtr->fileState.readDocumentProc        = nil;
  600.     frPtr->fileState.readDocumentHeaderProc  = nil;
  601.     frPtr->fileState.resizeContentProc       = nil;
  602.     frPtr->fileState.scrollFrameProc         = nil;
  603.     frPtr->fileState.undoFixupProc           = nil;
  604.     frPtr->fileState.windowCursorProc        = VHWindowCursor;
  605.     frPtr->fileState.writeDocumentProc       = nil;
  606.     frPtr->fileState.writeDocumentHeaderProc = nil;
  607.         /* View Hierarchy method declarations. */
  608.  
  609.     frPtr->fileState.attributes = kwVHAppWindow;
  610.  
  611.     /* Document-specific fields are already initialized to 0, so we do nothing. */
  612.  
  613.     for (window = nil; window = GetNextWindow(window, 0);) {
  614.         if (refFrHndl = (FileRecHndl)GetWRefCon(window)) {
  615.             if ((*refFrHndl)->fileState.defaultDoc) {
  616.                 (*frHndl)->d.vh.root = (*refFrHndl)->d.vh.root;
  617.                     /* This view hierarchy window, which isn't created yet, will reference
  618.                     ** the data in the topmost window that uses the default document
  619.                     ** architecture.  As the view hierarchy window is only for debugging
  620.                     ** purposes, there is no prevision to guarantee that the data being
  621.                     ** pointed to will continue to exist or continue to be valid.
  622.                     ** The document that this references could be closed, and therefore
  623.                     ** the reference would point to non-existent data.  (You are warned.) */
  624.                 return(noErr);
  625.             }
  626.         }
  627.     } 
  628.  
  629.     return(memFullErr);
  630.         /* Memory really isn't full.  We just need to pass back an error so that
  631.         ** the application knows that the view hierarchy document wasn't successfully
  632.         ** created.  It wasn't successfull created because it couldn't find any documents
  633.         ** that use the document hierarchy.  This really shouldn't occur, as the application
  634.         ** shouldn't have the menu option available for the view hierarchy window if there
  635.         ** is nothing to view.  However, since the view hierarchy window is just for
  636.         ** debugging, it seems annoying to demand that the application set the state of
  637.         ** the menu item correctly.  Returning any error here should be enough for the
  638.         ** application to be graceful. */
  639. }
  640.  
  641.  
  642.  
  643. /*****************************************************************************/
  644.  
  645.  
  646.  
  647. #pragma segment Window
  648. long    VHFileTypeSize(void)
  649. {
  650.     return(sizeof(ViewHierFileTypeRec));
  651. }
  652.  
  653.  
  654.  
  655. /*****************************************************************************/
  656.  
  657.  
  658.  
  659. #pragma segment Window
  660. void    VHRootInfo(TreeObjHndl root, char *cptr)
  661. {
  662.     ccat   (cptr, "$10: TRootObj:");
  663.     ccatchr(cptr, 13, 1);
  664.     ccat   (cptr, "  $00: undo        = $");
  665.     ccathex(cptr, '0', 8, 8, (long)mDerefUndo(root)->root);
  666.     ccatchr(cptr, 13, 1);
  667.     ccat   (cptr, "  $04: frHndl      = $");
  668.     ccathex(cptr, '0', 8, 8, (long)mDerefUndo(root)->frHndl);
  669.     ccatchr(cptr, 13, 1);
  670. }
  671.  
  672.  
  673.  
  674. /*****************************************************************************/
  675.  
  676.  
  677.  
  678. #pragma segment Window
  679. void    VHFileRecInfo(TreeObjHndl root, char *cptr)
  680. {
  681.     FileRecHndl    frHndl;
  682.     Str255        str;
  683.     char        hstate;
  684.     Rect        rct;
  685.     long        offset;
  686.  
  687.     frHndl = mDerefRoot(root)->frHndl;
  688.     hstate = LockHandleHigh((Handle)frHndl);
  689.  
  690.     ccat   (cptr, "(*frHndl)->fileState:");
  691.     ccatchr(cptr, 13, 1);
  692.     ccat   (cptr, "  sfType                  = '");
  693.     *(long *)str = (*frHndl)->fileState.sfType;
  694.     str[sizeof(long)] = 0;
  695.     ccat   (cptr, (char *)str);
  696.     ccat   (cptr, "'");
  697.     ccatchr(cptr, 13, 1);
  698.  
  699.     ccat   (cptr, "  defaultDoc              = ");
  700.     ccatdec(cptr, (*frHndl)->fileState.defaultDoc);
  701.     ccatchr(cptr, 13, 1);
  702.  
  703.     ccat   (cptr, "  movie                   = $");
  704.     ccathex(cptr, '0', 8, 8, (long)(*frHndl)->fileState.movie);
  705.     ccatchr(cptr, 13, 1);
  706.  
  707.     ccat   (cptr, "  movieResID              = ");
  708.     ccatdec(cptr, (*frHndl)->fileState.movieResID);
  709.     ccatchr(cptr, 13, 1);
  710.  
  711.     ccat   (cptr, "  movieFlags              = $");
  712.     ccathex(cptr, '0', 4, 4, (*frHndl)->fileState.movieFlags);
  713.     ccatchr(cptr, 13, 1);
  714.  
  715.     ccat   (cptr, "  movieDataRefWasChanged  = ");
  716.     ccatdec(cptr, (*frHndl)->fileState.movieDataRefWasChanged);
  717.     ccatchr(cptr, 13, 1);
  718.  
  719.     ccat   (cptr, "  docDirty                = ");
  720.     ccatdec(cptr, (*frHndl)->fileState.docDirty);
  721.     ccatchr(cptr, 13, 1);
  722.  
  723.     ccat   (cptr, "  modNum                  = ");
  724.     ccatdec(cptr, (*frHndl)->fileState.modNum);
  725.     ccatchr(cptr, 13, 1);
  726.  
  727.     ccat   (cptr, "  modTick                 = ");
  728.     ccatdec(cptr, (*frHndl)->fileState.modTick);
  729.     ccatchr(cptr, 13, 1);
  730.  
  731.     ccat   (cptr, "  readOnly                = ");
  732.     ccatdec(cptr, (*frHndl)->fileState.readOnly);
  733.     ccatchr(cptr, 13, 1);
  734.  
  735.     ccat   (cptr, "  refNum                  = ");
  736.     ccatdec(cptr, (*frHndl)->fileState.refNum);
  737.     ccatchr(cptr, 13, 1);
  738.  
  739.     ccat   (cptr, "  resRefNum               = ");
  740.     ccatdec(cptr, (*frHndl)->fileState.resRefNum);
  741.     ccatchr(cptr, 13, 1);
  742.  
  743.     ccat   (cptr, "  fss.vRefNum             = ");
  744.     ccatdec(cptr, (*frHndl)->fileState.fss.vRefNum);
  745.     ccatchr(cptr, 13, 1);
  746.  
  747.     ccat   (cptr, "  fss.parID               = $");
  748.     ccathex(cptr, '0', 8, 8, (*frHndl)->fileState.fss.parID);
  749.     ccatchr(cptr, 13, 1);
  750.  
  751.     ccat   (cptr, "  fss.name                = ");
  752.     pcpy   (str, (*frHndl)->fileState.fss.name);
  753.     p2c    (str);
  754.     ccat   (cptr, (char *)str);
  755.     ccatchr(cptr, 13, 1);
  756.  
  757.     ccat   (cptr, "  windowID                = ");
  758.     ccatnum(cptr, (*frHndl)->fileState.windowID, 10);
  759.     ccatchr(cptr, 13, 1);
  760.  
  761.     ccat   (cptr, "  window                  = $");
  762.     ccathex(cptr, '0', 8, 8, (long)(*frHndl)->fileState.window);
  763.     ccatchr(cptr, 13, 1);
  764.  
  765.     cptr += clen(cptr);
  766.  
  767.     ccat   (cptr, "  getDocWindow            = $");
  768.     ccathex(cptr, '0', 8, 8, (long)(*frHndl)->fileState.getDocWindow);
  769.     ccatchr(cptr, 13, 1);
  770.  
  771.     ccat   (cptr, "  calcFrameRgnProc        = $");
  772.     ccathex(cptr, '0', 8, 8, (long)(*frHndl)->fileState.calcFrameRgnProc);
  773.     ccatchr(cptr, 13, 1);
  774.  
  775.     ccat   (cptr, "  contentClickProc        = $");
  776.     ccathex(cptr, '0', 8, 8, (long)(*frHndl)->fileState.contentClickProc);
  777.     ccatchr(cptr, 13, 1);
  778.  
  779.     ccat   (cptr, "  contentKeyProc          = $");
  780.     ccathex(cptr, '0', 8, 8, (long)(*frHndl)->fileState.contentKeyProc);
  781.     ccatchr(cptr, 13, 1);
  782.  
  783.     ccat   (cptr, "  drawFrameProc           = $");
  784.     ccathex(cptr, '0', 8, 8, (long)(*frHndl)->fileState.drawFrameProc);
  785.     ccatchr(cptr, 13, 1);
  786.  
  787.     ccat   (cptr, "  freeDocumentProc        = $");
  788.     ccathex(cptr, '0', 8, 8, (long)(*frHndl)->fileState.freeDocumentProc);
  789.     ccatchr(cptr, 13, 1);
  790.  
  791.     ccat   (cptr, "  freeWindowProc          = $");
  792.     ccathex(cptr, '0', 8, 8, (long)(*frHndl)->fileState.freeWindowProc);
  793.     ccatchr(cptr, 13, 1);
  794.  
  795.     ccat   (cptr, "  imageProc               = $");
  796.     ccathex(cptr, '0', 8, 8, (long)(*frHndl)->fileState.imageProc);
  797.     ccatchr(cptr, 13, 1);
  798.  
  799.     ccat   (cptr, "  initContentProc         = $");
  800.     ccathex(cptr, '0', 8, 8, (long)(*frHndl)->fileState.initContentProc);
  801.     ccatchr(cptr, 13, 1);
  802.  
  803.     ccat   (cptr, "  readDocumentProc        = $");
  804.     ccathex(cptr, '0', 8, 8, (long)(*frHndl)->fileState.readDocumentProc);
  805.     ccatchr(cptr, 13, 1);
  806.  
  807.     ccat   (cptr, "  readDocumentHeaderProc  = $");
  808.     ccathex(cptr, '0', 8, 8, (long)(*frHndl)->fileState.readDocumentHeaderProc);
  809.     ccatchr(cptr, 13, 1);
  810.  
  811.     ccat   (cptr, "  resizeContentProc       = $");
  812.     ccathex(cptr, '0', 8, 8, (long)(*frHndl)->fileState.resizeContentProc);
  813.     ccatchr(cptr, 13, 1);
  814.  
  815.     ccat   (cptr, "  scrollFrameProc         = $");
  816.     ccathex(cptr, '0', 8, 8, (long)(*frHndl)->fileState.scrollFrameProc);
  817.     ccatchr(cptr, 13, 1);
  818.  
  819.     ccat   (cptr, "  undoFixupProc           = $");
  820.     ccathex(cptr, '0', 8, 8, (long)(*frHndl)->fileState.undoFixupProc);
  821.     ccatchr(cptr, 13, 1);
  822.  
  823.     ccat   (cptr, "  windowCursorProc        = $");
  824.     ccathex(cptr, '0', 8, 8, (long)(*frHndl)->fileState.windowCursorProc);
  825.     ccatchr(cptr, 13, 1);
  826.  
  827.     ccat   (cptr, "  writeDocumentProc       = $");
  828.     ccathex(cptr, '0', 8, 8, (long)(*frHndl)->fileState.writeDocumentProc);
  829.     ccatchr(cptr, 13, 1);
  830.  
  831.     ccat   (cptr, "  writeDocumentHeaderProc = $");
  832.     ccathex(cptr, '0', 8, 8, (long)(*frHndl)->fileState.writeDocumentHeaderProc);
  833.     ccatchr(cptr, 13, 1);
  834.  
  835.     cptr += clen(cptr);
  836.  
  837.     ccat   (cptr, "  attributes              = $");
  838.     ccathex(cptr, '0', 4, 4, (long)(*frHndl)->fileState.attributes);
  839.     ccatchr(cptr, 13, 1);
  840.  
  841.     ccat   (cptr, "  windowSizeBounds        = ($");
  842.     rct = (*frHndl)->fileState.windowSizeBounds;
  843.     ccathex(cptr, 0, 4, 4, rct.top);
  844.     ccat   (cptr, ",$");
  845.     ccathex(cptr, 0, 4, 4, rct.left);
  846.     ccat   (cptr, ",");
  847.     ccatchr(cptr, 13, 1);
  848.     ccatchr(cptr, ' ', 29);
  849.     ccat   (cptr, "$");
  850.     ccathex(cptr, 0, 4, 4, rct.bottom);
  851.     ccat   (cptr, ",$");
  852.     ccathex(cptr, 0, 4, 4, rct.right);
  853.     ccat   (cptr, ")");
  854.     ccatchr(cptr, 13, 1);
  855.  
  856.     ccat   (cptr, "  hScroll                 = $");
  857.     ccathex(cptr, '0', 8, 8, (long)(*frHndl)->fileState.hScroll);
  858.     ccatchr(cptr, 13, 1);
  859.  
  860.     ccat   (cptr, "  vScroll                 = $");
  861.     ccathex(cptr, '0', 8, 8, (long)(*frHndl)->fileState.vScroll);
  862.     ccatchr(cptr, 13, 1);
  863.  
  864.     ccat   (cptr, "  hScrollIndent           = ");
  865.     ccatdec(cptr, (*frHndl)->fileState.hScrollIndent);
  866.     ccatchr(cptr, 13, 1);
  867.  
  868.     ccat   (cptr, "  vScrollIndent           = ");
  869.     ccatdec(cptr, (*frHndl)->fileState.vScrollIndent);
  870.     ccatchr(cptr, 13, 1);
  871.  
  872.     ccat   (cptr, "  leftSidebar             = ");
  873.     ccatdec(cptr, (*frHndl)->fileState.leftSidebar);
  874.     ccatchr(cptr, 13, 1);
  875.  
  876.     ccat   (cptr, "  topSidebar              = ");
  877.     ccatdec(cptr, (*frHndl)->fileState.topSidebar);
  878.     ccatchr(cptr, 13, 1);
  879.  
  880.     ccat   (cptr, "  hArrowVal               = ");
  881.     ccatdec(cptr, (*frHndl)->fileState.hArrowVal);
  882.     ccatchr(cptr, 13, 1);
  883.  
  884.     ccat   (cptr, "  vArrowVal               = ");
  885.     ccatdec(cptr, (*frHndl)->fileState.vArrowVal);
  886.     ccatchr(cptr, 13, 1);
  887.  
  888.     ccat   (cptr, "  hPageVal                = ");
  889.     ccatdec(cptr, (*frHndl)->fileState.hPageVal);
  890.     ccatchr(cptr, 13, 1);
  891.  
  892.     ccat   (cptr, "  vPageVal                = ");
  893.     ccatdec(cptr, (*frHndl)->fileState.vPageVal);
  894.     ccatchr(cptr, 13, 2);
  895.  
  896.     cptr += clen(cptr);
  897.  
  898.     ccat   (cptr, "(*frHndl)->connect:");
  899.     ccatchr(cptr, 13, 1);
  900.     ccat   (cptr, "  windowTag[0]             = ");
  901.     ccatdec(cptr, (*frHndl)->connect.windowTag[0]);
  902.     ccatchr(cptr, 13, 1);
  903.  
  904.     ccat   (cptr, "  windowTag[1]             = ");
  905.     ccatdec(cptr, (*frHndl)->connect.windowTag[1]);
  906.     ccatchr(cptr, 13, 1);
  907.  
  908.     ccat   (cptr, "  connected                = ");
  909.     ccatdec(cptr, (*frHndl)->connect.connected);
  910.     ccatchr(cptr, 13, 1);
  911.  
  912.     ccat   (cptr, "  remoteLoc.descriptorType = '");
  913.     *(long *)str = (*frHndl)->connect.remoteLoc.descriptorType;
  914.     str[sizeof(long)] = 0;
  915.     ccat   (cptr, (char *)str);
  916.     ccat   (cptr, "'");
  917.     ccatchr(cptr, 13, 1);
  918.  
  919.     ccat   (cptr, "  remoteLoc.dataHandle     = $");
  920.     ccathex(cptr, '0', 8, 8, (long)(*frHndl)->connect.remoteLoc.dataHandle);
  921.     ccatchr(cptr, 13, 1);
  922.  
  923.     ccat   (cptr, "  remoteName    = ");
  924.     pcpy   (str, (*frHndl)->connect.remoteName);
  925.     p2c    (str);
  926.     ccat   (cptr, (char *)str);
  927.     ccatchr(cptr, 13, 1);
  928.  
  929.     ccat   (cptr, "  remoteZone    = ");
  930.     pcpy   (str, (*frHndl)->connect.remoteZone);
  931.     p2c    (str);
  932.     ccat   (cptr, (char *)str);
  933.     ccatchr(cptr, 13, 1);
  934.  
  935.     ccat   (cptr, "  remoteMachine = ");
  936.     pcpy   (str, (*frHndl)->connect.remoteMachine);
  937.     p2c    (str);
  938.     ccat   (cptr, (char *)str);
  939.     ccatchr(cptr, 13, 2);
  940.  
  941.     cptr += clen(cptr);
  942.  
  943.     ccat   (cptr, "(*frHndl)->d.doc.fhInfo:");
  944.     ccatchr(cptr, 13, 1);
  945.     ccat   (cptr, "  version       = ");
  946.     ccatdec(cptr, (*frHndl)->d.doc.fhInfo.version);
  947.     ccatchr(cptr, 13, 1);
  948.  
  949.     ccat   (cptr, "  printRecValid = ");
  950.     ccatdec(cptr, (*frHndl)->d.doc.fhInfo.printRecValid);
  951.     ccatchr(cptr, 13, 1);
  952.  
  953.     ccat   (cptr, "  print         = (char *)(*frHndl) + $");
  954.     offset  = (long)StripAddress(&(*frHndl)->d.doc.fhInfo.print);
  955.     offset -= (long)StripAddress(*frHndl);
  956.     ccathex(cptr, '0', 4, 4, (long)offset);
  957.     ccatchr(cptr, 13, 1);
  958.  
  959.     ccat   (cptr, "  structureRect = ($");
  960.     rct = (*frHndl)->d.doc.fhInfo.structureRect;
  961.     ccathex(cptr, 0, 4, 4, rct.top);
  962.     ccat   (cptr, ",$");
  963.     ccathex(cptr, 0, 4, 4, rct.left);
  964.     ccat   (cptr, ",$");
  965.     ccathex(cptr, 0, 4, 4, rct.bottom);
  966.     ccat   (cptr, ",$");
  967.     ccathex(cptr, 0, 4, 4, rct.right);
  968.     ccat   (cptr, ")");
  969.     ccatchr(cptr, 13, 1);
  970.  
  971.     ccat   (cptr, "  contentRect   = ($");
  972.     rct = (*frHndl)->d.doc.fhInfo.contentRect;
  973.     ccathex(cptr, 0, 4, 4, rct.top);
  974.     ccat   (cptr, ",$");
  975.     ccathex(cptr, 0, 4, 4, rct.left);
  976.     ccat   (cptr, ",$");
  977.     ccathex(cptr, 0, 4, 4, rct.bottom);
  978.     ccat   (cptr, ",$");
  979.     ccathex(cptr, 0, 4, 4, rct.right);
  980.     ccat   (cptr, ")");
  981.     ccatchr(cptr, 13, 1);
  982.  
  983.     ccat   (cptr, "  stdState      = ($");
  984.     rct = (*frHndl)->d.doc.fhInfo.stdState;
  985.     ccathex(cptr, 0, 4, 4, rct.top);
  986.     ccat   (cptr, ",$");
  987.     ccathex(cptr, 0, 4, 4, rct.left);
  988.     ccat   (cptr, ",$");
  989.     ccathex(cptr, 0, 4, 4, rct.bottom);
  990.     ccat   (cptr, ",$");
  991.     ccathex(cptr, 0, 4, 4, rct.right);
  992.     ccat   (cptr, ")");
  993.     ccatchr(cptr, 13, 1);
  994.  
  995.     ccat   (cptr, "  userState     = ($");
  996.     rct = (*frHndl)->d.doc.fhInfo.userState;
  997.     ccathex(cptr, 0, 4, 4, rct.top);
  998.     ccat   (cptr, ",$");
  999.     ccathex(cptr, 0, 4, 4, rct.left);
  1000.     ccat   (cptr, ",$");
  1001.     ccathex(cptr, 0, 4, 4, rct.bottom);
  1002.     ccat   (cptr, ",$");
  1003.     ccathex(cptr, 0, 4, 4, rct.right);
  1004.     ccat   (cptr, ")");
  1005.     ccatchr(cptr, 13, 1);
  1006.  
  1007.     ccat   (cptr, "  hDocSize      = ");
  1008.     ccatdec(cptr, (*frHndl)->d.doc.fhInfo.hDocSize);
  1009.     ccatchr(cptr, 13, 1);
  1010.  
  1011.     ccat   (cptr, "  vDocSize      = ");
  1012.     ccatdec(cptr, (*frHndl)->d.doc.fhInfo.vDocSize);
  1013.     ccatchr(cptr, 13, 1);
  1014.  
  1015.     HSetState((Handle)frHndl, hstate);
  1016. }
  1017.  
  1018.  
  1019.  
  1020.